package com.abe.bathsystem.adapter;


import android.content.Context;
import android.util.DisplayMetrics;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.abe.bathsystem.utils.ConstantBath;
import com.abe.libcore.core.screen.RelayoutTool;
import com.abe.libcore.utils.normal.CommonUtils;
import com.zhy.adapter.recyclerview.base.ViewHolder;

//添加像素布局适配
public class AbeViewHolder extends ViewHolder {
    public AbeViewHolder(Context context, View itemView) {
        super(context, itemView);
    }

    public static AbeViewHolder createViewHolder(Context context, View itemView) {
        AbeViewHolder holder = new AbeViewHolder(context, itemView);
        RelayoutTool.relayoutViewHierarchy(itemView, getScale(context));
        return holder;
    }

    public static AbeViewHolder createViewHolder(Context context,
                                                 ViewGroup parent, int layoutId) {
        View itemView = LayoutInflater.from(context).inflate(layoutId, parent,
                false);
        RelayoutTool.relayoutViewHierarchy(itemView, getScale(context));
        AbeViewHolder holder = new AbeViewHolder(context, itemView);
        return holder;
    }

    public static float getScale(Context context) {
        DisplayMetrics displayMetrics = context.getResources().getDisplayMetrics();
        float width = displayMetrics.widthPixels;
        int DesignWidth = CommonUtils.getMetaIntData(context, ConstantBath.META_DATA_DESIGN_WIDTH);
        if (DesignWidth == 0) return 1;
        return width / (float) (DesignWidth);
    }
}
